<template>
	<div class="page" data-page="singleUnitCard" style="background: rgb(236,243,243); z-index: 2;">
		<div class="page-content singleUnitCard-content ptr-content" @ptr:refresh="refreshCards">
        <div class="ptr-preloader">
          <div class="preloader"></div>
          <div class="ptr-arrow"></div>
        </div>
        <div class="single-cards-content">
          
        </div>
		</div>
	</div>
</template>
<style scoped>		
    .singleUnitCard-content .ptr-preloader{
      z-index: 9999;
    }
    .singleUnitCard-content .card{
        margin: 0px;
    }
    .singleUnitCard-content .card-view-single-style{
        margin-bottom: 10px;
        -webkit-box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24);
        box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24);
    }
</style>
<script>
	return {
    beforeCreate() {
      $(".singleUnitCard-content").empty();
    },
    created() {
    },
    beforeMount() {
    },
    mounted() {
      var self = this;
      self.getSingleCards();
      single_Orgid=self.loadOrgId.toString();
      single_OrgName=self.loadOrgName;
    },
    data: function () {
      return {
          list: [],  //定义接收的字段
          pageInitTime:0
      }    
    },
    methods: {
      //获取卡片数据
      getSingleCards:function(){
        var self = this;
        var $ = self.$$;
        $(".single-cards-content").empty();
        var orgId="";
        if(single_Orgid.toString().indexOf(",")==-1){
            orgId=single_Orgid;
        }else{
            orgId="";
        }
        Dao.unitStateList({
            userName: userInfor.accountName,
            deviceId: appKeyObj.deviceId,
            userAccount:userInfor.accountName,
            isMuilUnitUser:0,
            status:1,
            orgCode: platformCode || app.data.defaultPlatCode,
            orgId:orgId
        },function(data){
          data = data.sort(function(a,b){
              return a.orderNum-b.orderNum;
          });
          self.list = data;
          self.setSingleCardDom();
        },false);
      },
      //设置卡片Dom
      setSingleCardDom:function(){
        var self = this;
        var $ = self.$$;

        if(self.list && self.list.length>0){
          $(".single-cards-content").empty();
          for(var i = 0; i< self.list.length; i++){
              $(".single-cards-content").append('<div class="view  card-view-single-style card-view-single-'+self.list[i].id+'" id="single_'+self.list[i].name+'" data-name="'+self.list[i].name+'"></div>');
          }
            self.showSingleEveryCards();
        }
      },
      //卡片嵌入页面
      showSingleEveryCards:function(){
        var self = this;
        var $ = self.$$;
        
        //展示出各个模块
        if(self.list && self.list.length>0){
          for(var i = 0; i< self.list.length; i++){
            app.views.create('#single_'+self.list[i].name,{url: '/'+self.list[i].link+'/'});
          }
        }
      },
      //设置卡片高度
      getSingleCardsHeight:function(){
        var self = this;
        var $ = self.$$;
        if(self.list && self.list.length>0){
          for(var i = 0; i< self.list.length; i++){
            var $findDom = $("#single_"+self.list[i].name).find(".rdsp-card-view");
            if($findDom.length>0){
                $(".card-view-single-"+self.list[i].id).css("height",($findDom.height()+$findDom.offset().left*2)+"px");
            }
          }
        }
      },
      //刷新
      refreshCards: function (e, done) {
        if(done && e){
          var self = this;
          var $ = self.$$;
          setTimeout(function () {
            self.getSingleCards();
            // self.showSingleEveryCards();
            self.pageInitTime=1;
              done();
          }, 1000);
        }
      },
      dirBackToMoreUnit:function(){
        var self = this;
        var $ = self.$$;
        var router = this.$router;

        app.router.navigate("/main/",{
          animate:true, 
          reloadAll:true
        });
      }
    },
    on: {
      pageBeforeRemove: function(e, page) {},
      pageAfterOut: function(e, page) {
          //Do:离开页面后
          single_Orgid == "";
      },
      pageMounted:function(e, page) {},
      pageInit: function(e, page) {},
      pageAfterIn: function(e, page) {
        var self = this;
        var app = self.$app;
        var $ = self.$;
        self.pageInitTime = self.pageInitTime+1;
        if(self.pageInitTime == (self.list.length+1)){
          self.getSingleCardsHeight();
        }
      },
    }
  }
	
</script>